package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.domain.SysProduct;
import com.ruoyi.system.mapper.SysProductMapper;
import com.ruoyi.system.service.ISysProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品信息 服务层处理
 *
 * @author ruoyi
 */
@Service
public class SysProductServiceImpl implements ISysProductService {

    @Autowired
    private SysProductMapper productMapper;

    @Override
    public List<SysProduct> selectProductList(SysProduct product) {
        return productMapper.selectProductList(product);
    }

    @Override
    public List<SysProduct> selectProductAll() {
        return productMapper.selectProductAll();
    }

    @Override
    public SysProduct selectProductById(Long productId) {
        return productMapper.selectProductById(productId);
    }

    @Override
    public int deleteProductById(Long productId) {
        return productMapper.deleteProductById(productId);
    }

    @Override
    public int deleteProductByIds(Long[] productIds) {
        return productMapper.deleteProductByIds(productIds);
    }

    @Override
    public int updateProduct(SysProduct product) {
        return productMapper.updateProduct(product);
    }

    @Override
    public int insertProduct(SysProduct product) {
        return productMapper.insertProduct(product);
    }

    @Override
    public String checkProductNameUnique(SysProduct product) {
        Long productId = StringUtils.isNull(product.getProductId()) ? -1L : product.getProductId();
        SysProduct info = productMapper.checkProductNameUnique(product.getProductName());
        if (StringUtils.isNotNull(info) && info.getProductId().longValue() != productId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public String checkProductCodeUnique(SysProduct product) {
        Long productId = StringUtils.isNull(product.getProductId()) ? -1L : product.getProductId();
        SysProduct info = productMapper.checkProductCodeUnique(product.getProductName());
        if (StringUtils.isNotNull(info) && info.getProductId().longValue() != productId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
